HomeView = {}
local self = HomeView

self.view = UIBase()
self.view.name = "HomeView"
self.view:AddPath("ui/panels/home.gdmec")
self.view:AddPath("audio/mp3.gdmec")
self.view.onInit = function()
    self:OnInit()
end

self.view.onUnit = function()
    self:OnUnit()
end

function self:Close()
    self.view:Close()
end

function self:Open()
    self.view:Open()
end

function self:OnInit()
    AudioManager.PlayMusic("20001")

    self.uis = {}
    self.uis.BtnClose = self.view.go.transform:Find("BtnClose"):GetComponent(typeof(UnityEngine.UI.Button))
    self.uis.title = self.view.go.transform:Find("Title"):GetComponent(typeof(UnityEngine.UI.Text))
    self.uis.BtnClose.onClick:AddListener(
        function()
            self:Close()
        end
    )


    self.uis.BtnClose.gameObject:SetActive(false)
    self.uis.Content =  self.view.go.transform:Find("ScrollView/Viewport/Content") 
    self.uis.childPrefab =  self.view.go.transform:Find("ScrollView/Viewport/Content/ChildPrefab") 
    self.uis.childPrefab.gameObject:SetActive(false)

    local mine = self:MakeChild()
    mine.name.text = "扫雷"
    mine.btn.onClick:AddListener(
        function()
            mine.btn.gameObject.transform:DOShakeScale(0.1);
            MineView:Open()
        end
    )

    local astar = self:MakeChild()
    astar.name.text = "A*"
    astar.btn.onClick:AddListener(
        function()
            AStarView:Open()
        end
    )

    local test = self:MakeChild()
    test.name.text = "Test"
    test.btn.onClick:AddListener(
        function()
            TestView:Open()
        end
    )

    local mymine = self:MakeChild()
    mymine.name.text = "我的扫雷"
    mymine.btn.onClick:AddListener(
        function()
            MyMineView:Open()
        end
    )

end

function self:MakeChild()
    local go = UnityEngine.GameObject.Instantiate(self.uis.childPrefab,self.uis.Content)
    local child = {
        go = go,
        name = go.transform:Find("Name"):GetComponent(typeof(UnityEngine.UI.Text)),
        btn = go:GetComponent(typeof(UnityEngine.UI.Button))
    }
    child.go.gameObject:SetActive(true)
    return child
end

function self:OnUnit()
end
